--[[
   @brief    新版社交客户端承载
   @author   senpingtian
   @version  1.0
   @date     2019-11-08
--]]

pwg_social_model = {
    MAX_LASTEST_MSG_ENTRY = 3;
    enable_pwg_social = true;
    notice_status_operation_list = {};
    muted_user_query_rsp = nil;
};

function pwg_social_model:log(msg, core_msg)
    base_utility.log("[pwg_social_model]" .. msg, core_msg);
end;

function pwg_social_model:init()
    self:log("init.");
    local ret = comm_center.call_service("i_service_check_pwg_social_state", {});
    if nil == ret or not ret.is_enabled then
        self.enable_pwg_social = false;
    end
end;

function pwg_social_model:get_last_message()
    local unread_msgs = {};
    local unread_list = comm_center.call_service("i_service_new_social_query_unread_message", {});
    if nil == unread_list then
        return unread_msgs;
    end
    if nil ~= unread_list.msgs and type(unread_list.msgs) ~= "table" then
        return unread_msgs;
    end
    local msgs = unread_list.msgs or {};
    for idx, entry in ipairs(msgs) do
        if #unread_msgs >= self.MAX_LASTEST_MSG_ENTRY then
            break;
        end
        if nil ~= entry.lastest_msg then
            local msg_detail = {};
            msg_detail["count"] = entry.unread_num or 0;
            msg_detail["type"] = 0;
            msg_detail["id"] = entry.lastest_msg.sender_id;
            msg_detail["contact_id"] = entry.user_id;
            msg_detail["name"] = entry.lastest_msg.sender_nick;
            msg_detail["face_url"] = entry.lastest_msg.sender_face;
            msg_detail["send_time"] = entry.lastest_msg.send_time;
            local last_msg = {
                message = entry.lastest_msg.msg_content;
            };
            msg_detail["msg"] = last_msg;
            table.insert(unread_msgs, msg_detail);
        end
    end
    return unread_msgs;
end;

function pwg_social_model:push_notice_operation(user_id, data)
    if nil == user_id then return end;
    local user_id = tostring(user_id);
    if "" == user_id then return end;
    local ret = self.notice_status_operation_list[user_id];
    self.notice_status_operation_list[user_id] = data;
    return ret;
end;

function pwg_social_model:pop_notice_operation(user_id)
    return self:push_notice_operation(user_id);
end;
